package ltd.dujiabao.capability.application.rulemng;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ltd.dujiabao.capability.domain.capmng.cap.CapabilityIdentity;
import ltd.dujiabao.capability.domain.devmng.DevInfo;
import ltd.dujiabao.capability.domain.devmng.DevInfoRepository;
import ltd.dujiabao.capability.domain.rulemng.Support;
import ltd.dujiabao.capability.domain.rulemng.SupportFactory;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/13 12:01
 * @Desc :
 */
@Service
public class SupportServiceImpl implements SupportService {

    @Autowired
    private DevInfoRepository devInfoRepository;

    @Autowired
    private SupportFactory supportFactory;

    @Override
    public SupportResultDTO checkIfSupport(SupportDTO dto) {
        // 查询设备信息
        DevInfo devInfo = devInfoRepository.findByDevId(dto.getDevId());
        // 查询支持情况
        CapabilityIdentity identity =
                new CapabilityIdentity(devInfo.getDevModelId(), devInfo.getHardwareVer(), devInfo.getFirmwareVer());
        Support support = supportFactory.buildSupport(identity, dto.getFuncName());

        return new SupportResultDTO()
                .setSupport(support.support());
    }
}
